﻿using JiaNetFrame.Application.System.Services;
using JiaNetFrame.Core.controller;
using JiaNetFrame.Core.utils;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JiaNetFrame.Application.System
{
    /// <summary>
    /// 系统管理 > 用户管理
    /// </summary>
    [Route("api/system/[controller]")]
    public class UserController: BaseController, ICrudController
    {
        private readonly IUserService _userService;
        public UserController(IUserService userService)
        {
            _userService = userService;
        }
        ///// <summary>
        ///// 添加用户信息
        ///// </summary>
        ///// <returns></returns>
        //[HttpPost]
        //public string add()
        //{
        //    return "add";
        //}

        ///// <summary>
        ///// 删除用户信息
        ///// </summary>
        ///// <returns></returns>
        //[HttpDelete]
        //public string del()
        //{
        //    return "del";
        //}
        //[HttpPatch]
        //public string batchdel()
        //{
        //    return "batchDel";
        //}
        //[HttpPut]
        //public string edit()
        //{
        //    return "edit";
        //}
        //[HttpGet]
        //public string search()
        //{
        //    DataTable dt = _userService.search();
        //    string result = JsonHelper.ToJson(dt);
        //    return result;
        //}


        public JArray GetQueryData()
        {
            DataTable dt = _userService.search();
            String dataJson = dtToJson(dt);
            JArray jsonArray = JArray.Parse(dataJson);
            JArray jsonArray2 = (JArray)JsonConvert.DeserializeObject(dataJson);
            //return returnResult(dt, "获取成功", 200);
            JObject jObject = JObject.Parse(jsonArray2[0].ToString());

            return jsonArray;
        }

        public IActionResult GetQuery()
        {
            DataTable dt = _userService.search();
            return returnResult(dt,"获取成功",200);
        }

        public IActionResult PostAdd()
        {
            throw new NotImplementedException();
        }

        public IActionResult PutDel()
        {
            throw new NotImplementedException();
        }

        public IActionResult PutEdit()
        {
            throw new NotImplementedException();
        }
    }
}
